Completed
Push — master ( e88c19...17669b )
by Rain
03:00
created

AbstractViewNext.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 6 Features 0
Metric Value
cc 1
c 6
b 6
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.4285
1
2
import ko from 'ko';
3
4
import {delegateRun, inFocus} from 'Common/Utils';
5
import {KeyState, EventKeyCode} from 'Common/Enums';
6
import {$win, keyScope} from 'Common/Globals';
7
8
class AbstractViewNext
9
{
10
	constructor() {
11
		this.bDisabeCloseOnEsc = false;
12
		this.sDefaultKeyScope = KeyState.None;
13
		this.sCurrentKeyScope = this.sDefaultKeyScope;
14
15
		this.viewModelVisibility = ko.observable(false);
16
		this.modalVisibility = ko.observable(false).extend({rateLimit: 0});
17
18
		this.viewModelName = '';
19
		this.viewModelNames = [];
20
		this.viewModelDom = null;
21
	}
22
23
	/**
24
	 * @returns {void}
25
	 */
26
	storeAndSetKeyScope() {
27
		this.sCurrentKeyScope = keyScope();
28
		keyScope(this.sDefaultKeyScope);
29
	}
30
31
	/**
32
	 * @returns {void}
33
	 */
34
	restoreKeyScope() {
35
		keyScope(this.sCurrentKeyScope);
36
	}
37
38
	/**
39
	 * @returns {void}
40
	 */
41
	registerPopupKeyDown() {
42
		$win.on('keydown', (event) => {
43
			if (event && this.modalVisibility && this.modalVisibility())
44
			{
45
				if (!this.bDisabeCloseOnEsc && EventKeyCode.Esc === event.keyCode)
46
				{
47
					delegateRun(this, 'cancelCommand');
48
					return false;
49
				}
50
				else if (EventKeyCode.Backspace === event.keyCode && !inFocus())
51
				{
52
					return false;
53
				}
54
			}
55
56
			return true;
57
		});
58
	}
59
60
	cancelCommand() {} // eslint-disable-line no-empty-function
61
	closeCommand() {} // eslint-disable-line no-empty-function
62
}
63
64
export {AbstractViewNext, AbstractViewNext as default};
65